package com.gitee.wsl.common.chart.render.foreground.info

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.PointF
import com.gitee.wsl.common.chart.model.PlotAttrInfoItem
import com.gitee.wsl.common.ui.draw.type.Location

class PlotAttrInfoRender {

    val attrInfoList: MutableList<PlotAttrInfoItem> = mutableListOf<PlotAttrInfoItem>()
    /**
     * 绘制附加信息
     * @param canvas        画布
     * @param centerX        绘图区中心点X坐标
     * @param centerY        绘图区中心点Y坐标
     * @param plotRadius    当前半径
     */
    fun renderAttrInfo(canvas: Canvas, centerX: Float, centerY: Float, plotRadius: Float) {
        var radius = 0.0f
        val mPosPintF = PointF()
        attrInfoList.forEach { attrInfo->
            mPosPintF.x = centerX
            mPosPintF.y = centerY
            radius = plotRadius * attrInfo.attrInfoPosition
            when (attrInfo.attrInfoLocation) {
                Location.TOP -> mPosPintF.y = centerY - radius
                Location.BOTTOM -> mPosPintF.y = centerY + radius
                Location.LEFT -> mPosPintF.x = centerX - radius
                Location.RIGHT -> mPosPintF.x = centerX + radius
            }
            canvas.drawText(attrInfo.info, mPosPintF.x, mPosPintF.y, attrInfo.paint)
        } 
    }

    fun clearPlotAttrInfo() {
        attrInfoList.clear()
    }


    /**
     * 增加附加信息
     * @param position        显示方位
     * @param info            附加信息
     * @param infoPosRadiusPercentage    信息显示在总半径指定比例所在位置
     * @param paint        用来绘制用的画笔
     */
    fun addAttributeInfo(
        position: Location, info: String,
        infoPosRadiusPercentage: Float, paint: Paint
    ) {
        attrInfoList.add(PlotAttrInfoItem(position,info,infoPosRadiusPercentage,paint))
    }
}